<?php
namespace Catalog\Data;

/**
 *
 * @author Paolo Bertuzzo
 *        
 */
class LocalizedProductTextDao extends AbstractDao
{

    /**
     * 
     * @param integer $productId
     * @param string $language
     */
    public function get($productId, $language)
    {
        $query = $this->entityManager->createQuery('select lpt from Catalog\Entity\LocalizedProductText lpt ' .
             'where lpt.productId = ?1 and lpt.language = ?2');
        
        $query->setParameter(1, $productId);
        $query->setParameter(2, $language);
        $query->useResultCache(true);

        return $query->getResult();
    }

    /**
     * 
     * @param string $alias
     * @param string $language
     */
    public function getProductByAliasAndLanguage($alias, $language)
    {
        $query = $this->entityManager->createQuery('select p from Catalog\Entity\Product p, Catalog\Entity\LocalizedProductText lpt ' .
        		'where lpt.type = \'alias\' and lpt.text = ?1 and lpt.language = ?2 and p.productId = lpt.productId');
        
        $query->setParameter(1, $alias);
        $query->setParameter(2, $language);
        $query->useResultCache(true);
        
        return $query->getResult();
    }
    
}

?>